<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>管理员主页面</title>
</head>
<body>

<h1>管理员主页面</h1>
<div>未处理消息数：<span id="tipNum">0</span></div>

<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script>

    $(function (){

        //发送webSocket通信
        if (!"WebSocket" in window){
            alert("您的浏览器不支持 WebSocket!");
            return;
        }

        var ws = new WebSocket("ws://localhost:8080/webSocketServer");

        //打开事件
        ws.onopen = function()
        {
            // Web Socket 已连接上，使用 send() 方法发送数据
            ws.send("发送数据");
            alert("数据发送中...");
        };

        //接收服务器发送的消息
        ws.onmessage = function (evt)
        {
            var received_msg = evt.data;
            console.log(received_msg);
            var tipNum = $("#tipNum").text();
            console.log(tipNum++);
            $("#tipNum").html(tipNum++);
        };

        ws.onclose = function()
        {
            // 关闭 websocket
            alert("连接已关闭...");
        };



    })

</script>
</body>
</html>